<!-- 财务审核 -->
<template>
  <div class="page-main">
    <CustomForm
      :formInline="formInline"
      @onSubmit="onSubmit"
      @resetTable="resetTable"
      :exportBtn="true"
      @exportHandler="exportHandler"
      @expandChange="expandChange"
      :btnOnLine="true"
    >
      <el-form-item label="公司名称">
        <el-input v-model="formInline.company_name" placeholder="输入公司名称"></el-input>
      </el-form-item>
      <el-form-item label="货物名称">
        <el-input v-model="formInline.goods" placeholder="输入货物名称"></el-input>
      </el-form-item>
      <el-form-item label="总运单ID">
        <el-input v-model="formInline.add_id" placeholder="输入总运单ID"></el-input>
      </el-form-item>

      <el-form-item label="审核">
        <el-select v-model="formInline.xiugai" placeholder="选择审核状态" @change="changeStatusSelect">
          <el-option label="全部" :value="0"></el-option>
          <el-option label="未审核" :value="1"></el-option>
          <el-option label="已审核" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="推送时间">
        <el-date-picker
          v-model="pickerDateArr"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="(data) => changeDatePicker(data, 'auditing')"
          :picker-options="pickerOptions"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="状态">
        <el-select v-model="formInline.status" placeholder="选择状态" @change="changeStatusSelect">
          <el-option label="全部" :value="0"></el-option>
          <el-option label="未支付" :value="1"></el-option>
          <el-option label="已支付" :value="2"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="司机姓名">
        <el-input v-model="formInline.sjxm" placeholder="输入司机姓名"></el-input>
      </el-form-item>

      <el-form-item label="分运单ID">
        <el-input v-model="formInline.fyd" placeholder="输入分运单ID,多个分运单ID以逗号分隔"></el-input>
      </el-form-item>
      <el-form-item label="发货时间">
        <el-date-picker
          v-model="pickerDateArrGoods"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="(data) => changeDatePicker(data, 'goods')"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="到达时间">
        <el-date-picker
          v-model="pickerDateArrReach"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          @change="(data) => changeDatePicker(data, 'reach')"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="车牌号">
        <el-input v-model="formInline.cph" placeholder="输入车牌号"></el-input>
      </el-form-item>
      <!-- <el-form-item label="公司">
                <el-select v-model="formInline.statusId" placeholder="选择公司" @change="changeStatusSelect">
                    <el-option label="全部" :value="0"></el-option>
                    <el-option label="安阳总公司" :value="1"></el-option>
                    <el-option label="林州分公司" :value="2"></el-option>
                    <el-option label="安徽分公司" :value="3"></el-option>
                </el-select>
      </el-form-item>-->
      <el-form-item label="钉钉状态">
        <el-select
          v-model="formInline.approve_status"
          placeholder="选择审核状态"
          @change="changeStatusSelect"
        >
          <el-option label="全部" :value="0"></el-option>
          <el-option label="未发起" :value="1"></el-option>
          <el-option label="已发起" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属地区">
        <el-select v-model="formInline.area_status" placeholder="选择所属公司" @change="selectArea">
          <el-option label="全部" :value="-1"></el-option>
          <el-option
            v-for="(item, index) in getOfficesList"
            :key="item"
            :label="item"
            :value="index"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="锁定状态">
        <el-select v-model="formInline.is_lock" placeholder="选择锁定状态" @change="changeStatusSelect">
          <el-option label="全部" :value="0"></el-option>
          <el-option label="未锁定" :value="1"></el-option>
          <el-option label="已锁定" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <template #btnBoxHeader>
        <el-button type="success" @click="batchSetPrice">批量修改单价</el-button>
        <el-button type="success" @click="batchDD">钉钉批量审核</el-button>
      </template>
    </CustomForm>

    <div class="line">
      <div class="box">
        <el-checkbox v-model="selectAll" @change="selectAllChange"></el-checkbox>
      </div>
      <CustomDescriptions :data="descriptionsData" :styleBox="{ width: '98%' }"></CustomDescriptions>
    </div>

    <div class="main" v-loading="tableloading" :style="{height:mainHeight + 'px'}">
      <TableCard
        v-for="(item,index) in tableList"
        :key="item.yund_id"
        :form="item"
        @showPaymentBillDetail="showPaymentBillDetail"
        @syncPayInfo="syncPayInfo"
        @upWaybill="upWaybill"
        @lockBill="lockBill"
        @changeBillMoney="changeBillMoney"
        @changeShipMoney="changeShipMoney"
        @addNote="addNote"
        @contractHandler="contractHandler"
        @checkBillStatus="checkBillStatus"
        @selectChange="selectChange"
      />
    </div>
    <el-table
      v-if="false"
      :data="tableList"
      style="width: 100%"
      height="536"
      v-loading="tableloading"
      @selection-change="handleSelectionChange"
      border
      ref="multipleTable"
    >
      <el-table-column align="center" width="80">
        <template slot-scope="scope">
          <!-- <svg v-if="false"
                        style="width: 3em;height:1rem;vertical-align: -0.15em;fill: currentColor;overflow: hidden;"
                        aria-hidden="true">
                        <use xlink:href="#icon-prePayIcon" />
          </svg >-->
          <StatusTag :status="scope.row.advance_payment_status" :yund_id="scope.row.yund_id" />
          <StatusTag v-if="scope.row.is_lock == 1" :isError="true" :status="5" :lockReason="scope.row.reason" :yund_id="scope.row.yund_id" />
        </template>
      </el-table-column>
      <el-table-column type="selection" width="25" align="center" :selectable="selectableStatus"></el-table-column>
      <el-table-column
        prop="area_company"
        label="所属地区"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop label="运单ID" width="110" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.add_id + '-' + scope.row.yund_id }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="company_name"
        label="公司名称"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="goods" label="货物名称" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column
        prop="cph"
        label="车牌号"
        width="100"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="driver_name" label="司机姓名" width="100" align="center">
        <template slot-scope="scope">{{ $maskString(scope.row.driver_name) }}</template>
      </el-table-column>
      <el-table-column prop="th_time" label="发货时间" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span style="color: #409EFF;">{{ scope.row.th_time }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="time" label="到达时间" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span style="color: #67C23A;">{{ scope.row.dd_time }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dd_time" label="推送时间" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span style="color: #F56C6C;">{{ scope.row.add_time }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="to_address" label="到达地" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="shkg" label="收货重量" align="center" width="80"></el-table-column>
      <el-table-column prop="yfdj" label="运费单价" align="center" width="80"></el-table-column>
      <el-table-column prop="yfdj" label="含税金额" align="center" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.money_bill }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="zyf" label="实结金额" align="center" width="100"></el-table-column>
      <el-table-column prop="oil_money" label="油气(元)" align="center" width="80"></el-table-column>
      <el-table-column prop="oil_money" label="审核状态" align="center" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.xiugai == 0" style="color:red">未审核</span>
          <span v-else-if="scope.row.xiugai == 1" style="color:green">已审核</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="支付状态" align="center" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0" style="color:red">未支付</span>
          <span v-else-if="scope.row.status == 1" style="color:green">已支付</span>
          <span v-else-if="scope.row.status == 2" style="color:blue">二次支付</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="钉钉状态" align="center" width="80">
        <template slot-scope="scope">
          <span v-if="scope.row.batch_number_ding == '0'" style="color:red">未发起</span>
          <span v-if="scope.row.batch_number_ding != '0'" style="color:green">已发起</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            style="padding-left: 6px;padding-right: 6px;"
            @click="showPaymentBillDetail(scope.row)"
          >
            {{ scope.row.xiugai == 1 && scope.row.status == 1
            ? '查 看' : '审核' }}
          </el-button>

          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown" class="in-page-dropdown">
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="syncPayInfo(scope.row.yund_id)"
                >上传资金流水</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="upWaybill(scope.row)"
                >上传运单</el-button>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button
                  v-if="scope.row.status == 0"
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="lockBill(scope.row)"
                >{{ scope.row.is_lock == 1 ? '解锁' : '锁定' }}</el-button>
              </el-dropdown-item>

              <el-dropdown-item>
                <el-button
                  v-if="scope.row.xiugai == 1 && scope.row.status == 1"
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="changeBillMoney(scope.row)"
                >修改含税金额</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  v-if="scope.row.xiugai == 1 && scope.row.status == 1"
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="changeShipMoney(scope.row)"
                >运费增补修改</el-button>
              </el-dropdown-item>
              <el-dropdown-item>
                <el-button
                  v-if="scope.row.xiugai == 1 && scope.row.status == 1"
                  size="mini"
                  type="primary"
                  style="padding-left: 6px;padding-right: 6px;"
                  @click="addNote(scope.row)"
                >添加备注</el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="formInline.page"
      :page-sizes="$pageSizeList"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>

    <!-- <Pagination 
    :page="formInline.page" 
    :pageSize="formInline.pageSize" 
    :total="total"  
    @refreshTable="check" />-->

    <el-dialog
      top="10vh"
      class="dialog"
      title="钉钉批量审核"
      :close-on-click-modal="false"
      :visible.sync="dingDialog"
      width="40%"
    >
      <DingApprove v-if="dingDialog" :form="dingForm" @closeDialog="dingDialog = false;check()" />
    </el-dialog>

    <el-dialog
      top="5vh"
      class="dialog processDialog"
      title="查看财务审核信息"
      :close-on-click-modal="false"
      :visible.sync="dialogVisibleAuditing"
      width="80%"
    >
      <processAndpay
        v-if="dialogVisibleAuditing"
        :billDetail="billDetail"
        @closeDialog="closeDialog"
      />
    </el-dialog>
    <el-dialog
      top="5vh"
      class="dialog"
      title="批量货主支付"
      :close-on-click-modal="false"
      :visible.sync="dialogBatchPay"
      width="50%"
    >
      <catchPayDialog
        v-if="dialogBatchPay"
        :batchPayIds="batchPayIds"
        @closeDialog="closePayDialog"
      />
    </el-dialog>

    <el-dialog
      top="5vh"
      class="dialog"
      title="批量修改单价"
      :close-on-click-modal="false"
      :visible.sync="dialogSetPrice"
      width="50%"
    >
      <SetPriceDialog v-if="dialogSetPrice" :form="setPriceForm" @closeDialog="closePriceDialog" />
    </el-dialog>

    <el-dialog
      top="10vh"
      class="dialog"
      title="修改含税金额"
      :close-on-click-modal="false"
      :visible.sync="billMoneyDialog"
      width="30%"
    >
      <changeBillMoney
        v-if="billMoneyDialog"
        :row="billMoenyRow"
        @closeDialog="billMoneyDialog = false;"
        @sureDialog="billMoneyDialog = false,check()"
      />
    </el-dialog>

    <el-dialog
      top="10vh"
      class="dialog"
      title="运费增补修改"
      :close-on-click-modal="false"
      :visible.sync="shipMoneyDialog"
      width="30%"
    >
      <changeShipMoney
        v-if="shipMoneyDialog"
        :row="shipMoenyRow"
        @closeDialog="shipMoneyDialog = false;"
        @sureDialog="shipMoneyDialog = false,check()"
      />
    </el-dialog>

    <el-dialog
      top="10vh"
      class="dialog"
      title="添加备注"
      :close-on-click-modal="false"
      :visible.sync="noteDialog"
      width="30%"
    >
      <addNote
        v-if="noteDialog"
        :row="noteRow"
        @closeDialog="noteDialog = false;"
        @sureDialog="noteDialog = false,check()"
      />
    </el-dialog>

    <el-dialog
      class="wrongDialog"
      title="下列运单银行卡号错误,请重新选择"
      :visible.sync="wrongCardDialog"
      top="10vh"
      width="30%"
    >
      <!-- <span>银行卡号验证失败,请重新选择!</span> -->
      <el-table :data="wrongCardList" style="width: 100%">
        <el-table-column prop="add_id" label="运单ID" align="center">
          <template slot-scope="scope">{{ scope.row.add_id + '-' + scope.row.yund_id }}</template>
        </el-table-column>
        <el-table-column prop="sjxm" label="司机姓名"></el-table-column>
        <el-table-column prop="bank" label="银行卡号">
          <template slot-scope="scope">{{ scope.row.yinhang ? scope.row.yinhang : '--' }}</template>
        </el-table-column>
      </el-table>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="wrongCardDialog = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="运单日志"
      class="carTrace1"
      top="20vh"
      :close-on-click-modal="true"
      :visible.sync="billStausDialog"
      width="25%"
    >
      <billStatus v-if="billStausDialog" :row="billStatusInfo" @refreshTable="check" />
    </el-dialog>
  </div>
</template>

<script>
import {
  check,
  paymentBillDetail,
  uploadPay,
  uploadBill,
  exportData,
  lockBill
} from "@/api/businessUser/moneyManagment";
import { getContractLink } from "@/api/businessUser/waybill";
import TableCard from "@/components/TableCard/TableCard.vue"; //表格卡片组件
import DingApprove from "./components/DingApprove";
import processAndpay from "./components/processAndpay";
import catchPayDialog from "./components/catchPayDialog";
import changeBillMoney from "./components/changeBillMoney";
import changeShipMoney from "./components/changeShipMoney";
import billStatus from "../waybillManagement/components/billStatus";
import addNote from "./components/addNote";
import {  deepClone } from "@/utils/tool";
import {getToken, getUserId, getOfficesList} from "@/utils/auth";
import SetPriceDialog from "./components/SetPriceDialog";
import { validateAndCacheCardInfo } from "@/api/pageConfig";
import { timestampToTime } from "@/utils/tool.js";
export default {
  name: "moneyManageAuditing",
  //import引入的组件需要注入到对象中才能使用
  components: {
    processAndpay,
    catchPayDialog,
    SetPriceDialog,
    changeBillMoney,
    changeShipMoney,
    addNote,
    DingApprove,
    TableCard,
    billStatus
  },
  data() {
    //这里存放数据
    return {
      getOfficesList: getOfficesList(),
      formInline: {
        company_name: "",
        add_id: "",
        status: 0, //0全部1未支付2已支付
        xiugai: 0, //0全部1未修改2修改
        time: "",
        sjxm: "",
        cph: "",
        fyd: "",
        ftime: "",
        dtime: "",
        is_lock: 0, //0全部 1未锁定 2锁定
        // statusId: 0,
        page: 1,
        pageSize: 10,
        area_status: 0,
        goods: "",
        approve_status: 0 //钉钉状态
      },
      total: 0,
      tableList: [],
      pickerDateArr: "", //日期选择
      pickerDateArrGoods: "", //发货时间日期选择
      pickerDateArrReach: "", //到达时间日期选择
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      },

      descriptionsData: [
        {
          label: "总订单数",
          count: 0,
          unit: "(单)"
        },
        {
          label: "总金额",
          count: 0,
          unit: "(元)"
        },
        {
          label: "总重量",
          count: 0,
          unit: "(吨)"
        }
      ],
      dialogVisibleAuditing: false,

      tableloading: false,

      billDetail: {},

      billId: "",

      multipleSelection: [], //el-table select选中的数据
      dialogBatchPay: false,
      batchPayIds: null, //batchPayDialog需要的以逗号分隔的ids数据

      dialogSetPrice: false,
      setPriceForm: {
        id: "",
        price: null
      },
      wrongCardDialog: false,
      wrongCardList: [],

      billMoneyDialog: false,
      billMoenyRow: {},
      shipMoneyDialog: false,
      shipMoenyRow: {},
      noteRow: {},
      noteDialog: false,
      dingDialog: false,
      dingForm: [],
      mainHeight: 585, //内容区域高度
      selectAll: false,
      billStausDialog: false, //运单步骤弹框
      billStatusInfo: null //运单步骤详情
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    selectAllChange(val) {
      let tableList = this.$children.filter(item => item.name === "tableCard");
      tableList.forEach(item => {
        //先判断能否选中
        if(item.checkAble){
          item.checked1 = val;
          let form = item.form;
          if (!this.multipleSelection.some(t => t.yund_id == form.yund_id)) {
            this.multipleSelection.push(form);
          }
        }

      });
      if (!val) this.multipleSelection = [];
    },
    selectChange(row = {}, flag = true) {
      //以yund_id作为筛选表示
      let yund_id = row.yund_id;
      // this.multipleSelection
      if (flag) {
        //添加
        if (!this.multipleSelection.some(item => item.yund_id == yund_id)) {
          this.multipleSelection.push(row);
        }
      } else {
        //移除
        this.multipleSelection = this.multipleSelection.filter(
          item => item.yund_id != yund_id
        );
      }
      //判断如果不是所有全选 取消全选按钮
    },
    //折叠高度变化
    expandChange(flag) {
      if (!flag) {
        //折叠
        this.mainHeight = 589;
      } else {
        //展开
        this.mainHeight = 465;
      }
    },
    //合同链接
    async contractHandler(data) {
      let res = await getContractLink(data);
      if (res.code == 200) {
        window.open(res.url, "_blank");
      }
    },
    // 运单日志
    checkBillStatus(row) {
      this.billStatusInfo = row;
      this.billStausDialog = true;
    },
    //钉钉批次号为0的时候可选
    selectableStatus(row, index) {
      if (row.batch_number_ding == "0") {
        //已审核 未支付 未锁定的才可进行选中
        if (row.xiugai == 1 && row.status == 0 && row.is_lock == 0) {
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    },
    //获取一个月前的时间戳
    getOneMonthAgoTimestamp() {
      // const now = new Date(); // 当前时间
      // now.setMonth(now.getMonth() - 1); // 设置为一个月前的时间
      // return now.getTime(); // 获取时间戳
      // 获取当前时间的时间戳
      let currentTimestamp = Date.now();
      // 获取一天的毫秒数
      let oneDayInMilliseconds = 24 * 60 * 60 * 1000;
      // 计算一天前的时间戳
      let oneDayAgoTimestamp = currentTimestamp - oneDayInMilliseconds;
      return oneDayAgoTimestamp;
    },
    async check(pageData) {
      this.selectAll = false;
      this.multipleSelection = [];
      //重置所有勾选
      let tableList = this.$children.filter(item => item.name === "tableCard");
      tableList.forEach(item => {
        item.checked1 = false;
      });
      // if(pageData){
      //   this.formInline.page = pageData.page;
      //   this.formInline.pageSize = pageData.pageSize;
      // }
      this.tableloading = true;
      let res = await check(this.formInline);
      if (res.code == 200) {
        this.total = res.data.count;
        this.descriptionsData[0].count = res.data.count;
        this.descriptionsData[1].count = res.data.money;
        this.descriptionsData[2].count = res.data.weight;
        this.tableList = res.data.list.data;
      }

      this.tableloading = false;
    },
    onSubmit() {
      this.formInline.page = 1;
      this.formInline.fyd = this.formInline.fyd.replace(
        new RegExp("，", "gm"),
        ","
      );
      this.check();
    },
    resetTable() {
      this.formInline = {
        company_name: "",
        add_id: "",
        status: 0, //0全部1未支付2已支付
        xiugai: 0, //0全部1未修改2修改
        time: "",
        sjxm: "",
        cph: "",
        fyd: "",
        ftime: "",
        goods: "",
        is_lock: 0,
        // statusId: "",
        page: 1,
        pageSize: 10,
        area_status: 0,
        approve_status: 0 //钉钉状态
      };
      this.pickerDateArr = ""; //日期选择
      this.pickerDateArrGoods = ""; //发货时间日期选择
      this.pickerDateArrReach = ""; //到达时间日期选择

      this.check();
    },
    changeStatusSelect() {
      //状态发生改变回调函数
      this.formInline.page = 1;
      this.check();
    },
    changeDatePicker(data, type) {
      //
      if (type == "auditing") {
        if (data) {
          this.formInline.time = data.join(" - ");
        } else {
          this.formInline.time = "";
        }
      }
      if (type == "goods") {
        if (data) {
          this.formInline.ftime = data.join(" - ");
        } else {
          this.formInline.ftime = "";
        }
      }
      if (type == "reach") {
        if (data) {
          this.formInline.dtime = data.join(" - ");
        } else {
          this.formInline.dtime = "";
        }
      }
    },
    handleCurrentChange(page) {
      this.formInline.page = page;
      this.check();
    },

    handleSizeChange(pagesize) {
      this.formInline.pageSize = pagesize;
      this.check();
    },
    async showPaymentBillDetail(item) {
      this.billId = item.id;
      let result = await paymentBillDetail({
        id: item.id
      });
      if (result.code == 200) {
        this.billDetail = result.data;
        this.dialogVisibleAuditing = true;
      }
    },
    closeDialog() {
      this.dialogVisibleAuditing = false;
      this.check();
    },
    syncPayInfo(yund_id) {
      this.$confirm("确定要同步平台支付信息吗？", "同步平台支付信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          let res = await uploadPay({
            yund_id
          });
          if (res.code == 200) {
            this.$message.success(res.msg);
          }
        })
        .catch(() => {});
    },
    upWaybill(row) {
      this.$confirm("确定要重新上传运单吗？", "运单上传", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          let res = await uploadBill({
            yund_id: row.yund_id,
            id: row.id
          });
          if (res.code == 200) {
            this.$message.success(res.msg);
          }
        })
        .catch(() => {});
    },
    //锁定或解锁订单
    lockBill(row){
        if(row.is_lock == 1){
          //解锁
          this.$confirm(`确定要解锁此订单吗？`, {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(async () => {
            let res = await lockBill({
              is_lock: 0,
              yund_id: row.yund_id
            });
            if (res.code == 200) {
              this.$message.success('操作成功！');
              this.check();
            }
          }).catch(() => {});
        }else{
          //锁定
          this.$prompt('请输入锁定理由', '锁定运单', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPlaceholder:'锁定理由',
            inputValidator:(val)=>{
              return val ? true : '锁定理由不能为空!'
            },
          }).then(async ({ value }) => {
            let res = await lockBill({
              is_lock: 1,
              yund_id: row.yund_id,
              reason:value
            });
            if (res.code == 200) {
              this.$message.success('操作成功！');
              this.check();
            }
          }).catch(() => {  
          });
        }
    },
    exportHandler() {
      //导出数据

      //出审核 状态 所属地区这些默认数据外 用户必须操作输入别的筛选项才可以进行条件导出
      let keyList = ["xiugai", "status", "area_status", "page", "pageSize"];
      let exportAble = false;
      Object.keys(this.formInline).forEach(item => {
        if (!keyList.includes(item)) {
          if (this.formInline[item]) {
            //其余项存在值
            exportAble = true;
          }
        }
      });
      if (!exportAble) {
        this.$message.error("请输入任意条件 ！");
        return;
      }
      // console.log(`https://api.zhgylgl.com/api/admin/exportData?status=${this.formInline.status}&xiugai=${this.formInline.xiugai}&time=${this.formInline.time}&company_name=${this.formInline.company_name}&token=${getToken()}&userId=${getUserId()}`);
      window.open(
        `
            https://api.zhgylgl.com/api/admin/exportData?
            status=${this.formInline.status}&
            xiugai=${this.formInline.xiugai}&
            time=${this.formInline.time}&
            add_id=${this.formInline.add_id}&
            sjxm=${this.formInline.sjxm}&
            cph=${this.formInline.cph}&
            fyd=${this.formInline.fyd}&
            ftime=${this.formInline.ftime}&
            dtime=${this.formInline.dtime}&
            area_status=${this.formInline.area_status}&
            company_name=${this.formInline.company_name}&
            goods=${this.formInline.goods}&
            token=${getToken()}&
            userId=${getUserId()}
            `,
        "_blank",
        ""
      );
    },
    selectArea() {
      this.check();
    },
    // selectableStatus(row, index) {
    //     if (row.status == 0 && row.xiugai == 1 && row.area == 0) {//已审核 未支付状态才能true,且必须是总公司才行
    //         if (this.multipleSelection.includes(row)) {
    //             // 已选择的行，可取消选择
    //             return true;
    //         } else if (this.multipleSelection.length >= 15 && !row.selected) {
    //             // 超过最大选择条数（15），且当前行未被选中时，禁用
    //             return false;
    //         } else {
    //             // 其他情况下可选
    //             return true;
    //         }
    //     } else {
    //         return false
    //     }
    // },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    async batchDD() {
      //批量钉钉审核要求 1.每条数据的批次号(batch_number_ding)为0 2.公司名称都为同一家
      let length = this.multipleSelection.length;
      if (length == 0) {
        this.$message.error("请先选中要审核的数据!");
        return;
      } else {
        console.log("this.multipleSelection", this.multipleSelection);
        let list = this.multipleSelection;
        let companyList = [...new Set(list.map(item => item.company_name))];
        if (companyList.length > 1) {
          this.$message.error("只能钉钉批量审核同一家公司运单数据!");
          return;
        }
        if (length > 100) {
          this.$message.error("钉钉批量审核数据最多选择100条!");
          return;
        }
        this.dingDialog = true;
        this.dingForm = deepClone(list);
      }
    },
    async batchPay() {
      //批量修改运单状态
      let length = this.multipleSelection.length;
      if (length == 0) {
        this.$message.error("请先选中要支付的数据!");
        return;
      } else if (length > 1) {
        let companyName = this.multipleSelection[0].company_name;
        let companyNameEvery = this.multipleSelection.every(item => {
          return item.company_name == companyName;
        });
        if (!companyNameEvery) {
          this.$message.error("只能选中同一家公司数据!");
          return;
        }
      }

      if (length > 15) {
        this.$message.error("批量支付单次最多选择15条!");
        return;
      }

      if (
        !this.multipleSelection.every(item => {
          return item.status == 0 && item.xiugai == 1 && item.area == 0;
        })
      ) {
        this.$message.error("选中数据不符合要求!");
        return;
      }

      //校验银行卡号
      //验证卡号
      const cardLoading = this.$loading({
        lock: true,
        text: "验证银行卡号中...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.5)",
        customClass: "loadingCss"
      });

      this.wrongCardList = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        let item = this.multipleSelection[i];
        let card = item.bank;
        let result = await validateAndCacheCardInfo(card);
        if (!result.validated) {
          //验证失败
          this.wrongCardList.push(item);
          break;
        }
      }
      cardLoading.close();
      if (this.wrongCardList.length > 0) {
        //存在验证失败的卡号 结束支付并提示
        this.$message.error(`银行卡号验证失败,请重新选择!`);
        this.wrongCardDialog = true;
        return;
      }

      this.batchPayIds = this.multipleSelection.reduce((prev, curr, index) => {
        return (
          prev +
          curr.id +
          (index == this.multipleSelection.length - 1 ? "" : ",")
        );
      }, "");

      this.dialogBatchPay = true;
    },
    closePayDialog() {
      this.dialogBatchPay = false;
      this.check();
    },
    async batchSetPrice() {
      
      //批量修改单价回调
      if (this.multipleSelection.length === 0) {
        this.$message.error("请先选中要修改的数据!");
        return;
      }
      //存在已支付的运单不进行修改
      if (this.multipleSelection.some(item => item.status == 1)) {
        this.$message.error("存在已支付的运单,无法修改单价!");
        return;
      }
      this.setPriceForm.id = this.multipleSelection.reduce(
        (prev, curr, index) => {
          return (
            prev +
            curr.id +
            (index == this.multipleSelection.length - 1 ? "" : ",")
          );
        },
        ""
      );
      this.dialogSetPrice = true;
    },
    closePriceDialog() {
      this.dialogSetPrice = false;
      this.check();
    },
    //修改含税金额
    changeBillMoney(row) {
      this.billMoenyRow = row;
      this.billMoneyDialog = true;
    },
    changeShipMoney(row) {
      this.shipMoenyRow = row;
      this.shipMoneyDialog = true;
    },
    addNote(row) {
      this.noteRow = row;
      this.noteDialog = true;
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    if (this.$route.query) {
      if (this.$route.query.xiugai) {
        this.formInline.xiugai = Number(this.$route.query.xiugai);
      }
      if (this.$route.query.status) {
        this.formInline.status = Number(this.$route.query.status);
      }
    }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    //到达时间限定一个月
    let prevTime = this.getOneMonthAgoTimestamp();
    let currentTime = Date.now();
    this.pickerDateArrReach = [
      timestampToTime(prevTime),
      timestampToTime(currentTime)
    ];
    this.formInline.dtime = this.pickerDateArrReach.join(" - ");

    this.check();
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
::v-deep .el-pagination {
  margin-top: 10px;
}
.main {
  height: 465px;
  overflow: auto;
}
.line {
  display: flex;
  align-items: center;
  justify-content: space-between;
 
  .box{
    border:1px solid #EBEEF5;
    padding-left: 10px;
    width: 2%;
    height: 47px;
    border-right: none;
    border-radius: 3px;
    display: flex;
    align-items: center;
    // justify-content: center;

  }
}
.processDialog {
  ::v-deep .el-dialog {
    height: 88vh;

    .el-dialog__body {
      height: calc(88vh - 55px);
      overflow: hidden;
      padding: 10px;
    }
    .el-form-item {
      margin-bottom: 15px;
    }
  }
}

::v-deep .el-table .el-table__cell {
  padding: 10px 0;

  .cell {
    padding-left: 2px;
    padding-right: 2px;
  }
}
</style>